/**
 * anis.darwich
 */

package clubhouse.communication;

import java.util.Vector;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import clubhouse.motioncommand.MotionCommand;

public class TransmissionFifo {
	private final static Logger log = Logger.getLogger(TransmissionFifo.class);
	
	private Vector<MotionCommand> motionCom;
	
	public TransmissionFifo() {
		PropertyConfigurator.configure("log4j.properties");
		this.motionCom = new Vector<MotionCommand>(5,1);
	}
	
	protected Object getLock() {
		return this;
	}
	
	public void txMotionCom(MotionCommand msg) {
		synchronized(this.getLock()) {
			this.motionCom.add(msg);
			log.debug("Added "+ msg.toHexPrint() + " to motionCom\n");
		}
	}
	
	public MotionCommand getMotionCom() {
		synchronized(this.getLock()) {
			if (this.motionCom.size() != 0) {
				MotionCommand tmp = this.motionCom.firstElement();
				this.motionCom.remove(0);
				log.debug("Retrieved "+ tmp.toHexPrint() + " from motionCom\n");
				return tmp;
			} else {
				return null;
			}
		}
	}
	
	public int motionComAvailable() {
		return this.motionCom.size();
	}
}
